<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop" ref="buttondiv">
            <table class="table1style" border="0" style="font-size: 13px; width: 100%">
                <tr>
                    <td align="right">送出人：</td>
                    <td>
                        <rm-ddl-common @change="userinfochange" datatype="userinfo" dataname="用户" v-model="senduser" :width="ShowLeft == '0' ? '110px' : '100%'" :clearable="false"></rm-ddl-common>
                    </td>
                    <td align="right">
                        <div v-if="transtype == '5'">送出医院</div>
                        <div v-else-if="transtype == '3'">送出工作组</div>
                        <div v-else>送出科室</div>
                    </td>
                    <td :colspan="ShowLeft == '0' ? '1' : '4'">
                        <div v-if="transtype == '5'">
                            <rm-ddl-common datatype="hospital" dataname="医院" v-model="senddept" :width="ShowLeft == '0' ? '110px' : '100%'" key="0" :clearable="false"></rm-ddl-common>
                        </div>
                        <div v-else-if="transtype == '3'">
                            <rm-ddl-common datatype="labgroup" dataname="检验工作组" v-model="senddept" :width="ShowLeft == '0' ? '110px' : '100%'" key="1" :clearable="false"></rm-ddl-common>
                        </div>
                        <div v-else>
                            <rm-ddl-common datatype="dept" dataname="科室" v-model="senddept" :width="ShowLeft == '0' ? '110px' : '100%'" key="2" :clearable="false"></rm-ddl-common>
                        </div>
                    </td>
                    <td v-show="ShowLeft == '0'"><i class="el-icon-right"></i></td>
                    <td v-show="ShowLeft == '0'" align="right">
                        <div v-if="transtype == '5'">接收医院</div>
                        <div v-else-if="transtype == '3'">接收工作组</div>
                        <div v-else>接收科室</div>
                    </td>
                    <td v-show="ShowLeft == '0'" align="left">
                        <div v-if="transtype == '5'">
                            <rm-ddl-common datatype="hospital" dataname="医院" v-model="rcvdept" :width="ShowLeft == '0' ? '110px' : '100%'" key="3"></rm-ddl-common>
                        </div>
                        <div v-else-if="transtype == '3'">
                            <rm-ddl-common datatype="labgroup" dataname="检验工作组" v-model="rcvdept" :width="ShowLeft == '0' ? '110px' : '100%'" key="4"></rm-ddl-common>
                        </div>
                        <div v-else>
                            <rm-ddl-common datatype="dept" dataname="科室" v-model="rcvdept" :width="ShowLeft == '0' ? '110px' : '100%'" key="5"></rm-ddl-common>
                        </div>
                    </td>
                    <td>标本总数：{{ samplecnt }}</td>
                    <td>
                        <div v-show="ShowLeft == '0'" style="padding-left: 50px">包条码号：{{ packagebarcode }}</div>
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold; font-size: 15px" align="right">条码号：</td>
                    <td colspan="6">
                        <el-input v-model="txtbarcode" clearable placeholder="请扫描条码号" @keyup.enter.native="scanBarcode(txtbarcode)" style="width: 100%" size="medium" ref="barcode" id="barcodediv" @focus="HightlightPos(txtbarcode)" :disabled="this.isused"></el-input>
                    </td>
                    <td :width="buttonwidth"></td>
                    <td align="right">
                        <el-button icon="el-icon-delete" @click.native="btnDelete">删除</el-button>
                        <el-button v-if="this.isshowrecive" icon="el-icon-truck" @click.native="btnRecive">交接</el-button>
                        <el-button v-if="this.isshowsend" icon="el-icon-truck" @click.native="btnSend" :disabled="this.issend">送出</el-button>
                        <el-button icon="el-icon-printer" @click.native="btnPrintBarcode('All')">打印条码</el-button>
                        <el-button icon="el-icon-printer" @click.native="btnPrintList($event)">打印清单</el-button>
                        <el-button icon="el-icon-close" @click.native="btnClear">清除</el-button>
                        <el-button icon="el-icon-close" @click.native="btnClearAll" v-show="this.ShowLeft == '1'">全部清除</el-button>
                        <el-button icon="el-icon-search" @click="BtnHistoryQuery">打包记录</el-button>
                        <el-button icon="el-icon-setting" @click.native="btnSetting">设置</el-button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pagecenter" :key="hidkey">
            <rm-layout-left splitcolor="#F8F8FF" movingcolor="#00ff00" :splitwidth="leftsplit" :fixsize="LeftWidth" :minfixsize="80" :canDrag="false">
                <template v-slot:fix>
                    <vxe-table :data.sync="list" :loading="leftloading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" :edit-config="{ showIcon: false }" @cell-dblclick="RowPrintList" @current-change="leftChangeEvent" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="leftxTable" resizable show-overflow size="mini" stripe header-align="center">
                        <vxe-table-column field="operate" sortable title="操作" width="70" align="center">
                            <template v-slot="{ row }">
                                <div @click="rowclick(row)"><i class="el-icon-truck" style="font-size: 15px; color: #0095d9; cursor:pointer;">送出</i></div>
                                <!-- <el-button @click.native="rowclick(row)">送出</el-button> -->
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="packagebarcode" sortable title="包条码" width="100"></vxe-table-column>
                        <vxe-table-column field="samplecount" sortable title="标本数" width="66"></vxe-table-column>
                        <vxe-table-column field="reclabgroupid" sortable title="接收工作组" width="88" :formatter="formatFun" v-if="transtype == '3'"></vxe-table-column>
                        <vxe-table-column field="receivedept" sortable title="接收部门" width="88" :formatter="formatFun" v-else></vxe-table-column>
                        <!-- <vxe-table-column field="printdt" sortable title="打印时间" width="130"></vxe-table-column> -->
                        <vxe-table-column field="status" sortable title="状态" width="70"></vxe-table-column>
                        <vxe-table-column field="lastbarcode" sortable title="最后一个标本条码号" width="140"> </vxe-table-column>
                        <vxe-table-column field="lastpatname" sortable title="最后一个病人姓名" width="140"> </vxe-table-column>
                        <vxe-table-column field="transtype" sortable title="传递类型" width="80" :edit-render="{ name: 'select', options: $opt.TransType }"></vxe-table-column>
                        <!--  <vxe-table-column field="perform_dept" sortable title="传递记录号" width="100"></vxe-table-column> -->
                        <!-- <vxe-table-column field="createuser" sortable title="创建者" width="100"></vxe-table-column>
                        <vxe-table-column field="createtime" sortable title="创建时间" width="100"></vxe-table-column>
                        <vxe-table-column field="senddept" sortable title="送出部门" width="90"></vxe-table-column>
                        <vxe-table-column field="senduser" sortable title="送出人" width="90"></vxe-table-column>
                        <vxe-table-column field="transtime" sortable title="交接时间" width="130"></vxe-table-column>
                        <vxe-table-column field="recieveuser" sortable title="接受者" width="100"></vxe-table-column>
                        <vxe-table-column field="comments" sortable title="备注" width="120"></vxe-table-column> -->
                        <!-- <vxe-table-column field="operate" sortable title="操作" width="70" fixed="right" align="center">
                            <template v-slot="{row}">
                                <el-button @click.native="rowclick(row)">送出</el-button>
                            </template>
                        </vxe-table-column> -->
                        <template v-slot:fix>
                            <div style="font-size: 17px; padding-top: 3px; background-color: #fff; text-align: center; cursor: pointer" @click="ShowAllData">
                                <span style="color: blue; font-weight: bold">标本总数: {{ samplecnt }}</span>
                            </div>
                        </template>
                    </vxe-table>
                </template>
                <rm-layout-right splitcolor="#F8F8FF" movingcolor="#0000ff" :splitwidth="5" :fixsize="300">
                    <template v-slot:fix>
                        <vxe-table show-overflow border ref="xTable2" height="auto" row-id="id" size="mini" :select-config="{ reserve: true }" :data.sync="detail" show-header-overflow highlight-current-row highlight-hover-row resizable stripe>
                            <vxe-table-column field="seq" title="序号" width="50" align="center"></vxe-table-column>
                            <vxe-table-column field="req_itemname" title="申请项目名称 " width="160" header-align="center"></vxe-table-column>
                            <vxe-table-column field="item_price" title="实际价格" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="qty" title="数量" width="40" header-align="center"></vxe-table-column>
                            <vxe-table-column field="amount" title="金额" width="50" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_itemcode" title="申请项目代码" width="110" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_itemcode" title="HIS原始项目代码" width="120" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_recordid" title="HIS中对应记录号" width="120" header-align="center"></vxe-table-column>
                            <vxe-table-column field="combitemna" title="所属组合项目简称" width="120" header-align="center"></vxe-table-column>
                            <vxe-table-column field="base_price" title="理论/区域价格" width="94" header-align="center"></vxe-table-column>
                            <vxe-table-column field="stat_flag" title="统计标志" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="other_flag" title="其它标志" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="status" title="状态" width="58" header-align="center"></vxe-table-column>
                            <vxe-table-column field="lab_add" title="实验室添加标志" width="110" header-align="center"></vxe-table-column>
                            <vxe-table-column field="add_dt" title="添加时间" width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="add_user" title="添加用户" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_groupid" title="分单类别ID " width="97" header-align="center"></vxe-table-column>
                            <vxe-table-column field="charge_flag" title="计价标志" width="62" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_refcol1" title="HIS表相关字段1" width="117" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_refcol2" title="HIS表相关字段2 " width="117" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_refcol3" title="HIS表相关字段3 " width="117" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reportid" title="报告ID " width="80" header-align="center"></vxe-table-column>
                        </vxe-table>
                    </template>
                    <div style="height: 100%; width: 100%; background-color: #ddccbb">
                        <vxe-table show-overflow ref="xTable1" height="auto" row-id="id" :select-config="{ reserve: true }" :keyboard-config="keyConfig" :row-class-name="RowClassName" :cell-class-name="cellClassName" :keyboard-local-config="keyLocalConfig" :data.sync="masterList" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @current-change="detailretrieve" :edit-config="{ showIcon: false }">
                            <vxe-table-column field="req_groupna" title="分单类别" width="106" header-align="center">
                                <template v-slot="{ row }">
                                    <div v-bind:style="{ background: $pub.ColorChange(row.tube_color), color: $pub.colorConvert(row.tube_color) }" style="width: 120px">{{ row.req_groupna }}</div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="req_deptname" title="申请科室" width="104" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_wardname" title="病人病区 " width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_bedno" title="床号 " width="67" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_name" title="姓名 " width="67" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_sexname" title="性别 " width="48" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="req_statname" title="申请状态 " width="88" header-align="center"></vxe-table-column>
                            <vxe-table-column field="barcode" title="条码号 " width="115" header-align="center"></vxe-table-column>
                            <vxe-table-column field="emer_flag" title="加急 " width="50" header-align="center" align="center">
                                <template v-slot="{ row }">
                                    <div style="color: red">{{ row.emer_flag == "0" ? "" : "急" }}</div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="sample_items" title="项目描述 " width="203" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reject_reason" title="退回原因 " width="205" header-align="center"></vxe-table-column>
                            <vxe-table-column field="base_amount" title="基准总金额 " width="85" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="pat_no" title="病人号 " width="105" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_docname" title="申请医生 " width="75" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_typename" title="病人类型 " width="87" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="create_dt" title="条码生成时间 " width="130" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="create_username" title="条码生成用户 " width="104" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reject_username" title="退回用户 " width="90" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reject_dt" title="退回时间 " width="98" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="print_dt" title="打印日期 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="print_username" title="打印用户 " width="78" header-align="center"></vxe-table-column>
                            <vxe-table-column field="print_count" title="打印次数 " width="78" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="sampled_dt" title="采样时间 " width="121" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="sampled_username" title="采样用户 " width="93" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_dt" title="申请日期 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="pat_diag" title="临床诊断 " width="133" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_agestr" title="年龄字串 " width="78" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_id" title="病人唯一号 " width="107" header-align="center"></vxe-table-column>
                            <vxe-table-column field="inp_date" title="入院日期 " width="93" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="send_dt" title="护工交接时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="send_username" title="送出护工 " width="93" header-align="center"></vxe-table-column>
                            <vxe-table-column field="recieve_dt" title="检验科接收时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="recieve_username" title="检验科接收用户 " width="123" header-align="center"></vxe-table-column>
                            <vxe-table-column field="charge_dt" title="计价时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                            <vxe-table-column field="charge_username" title="计价人 " width="74" header-align="center"></vxe-table-column>
                            <vxe-table-column field="amount" title="实收总金额 " width="100" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="charge_flag" title="收费标志 " width="73" header-align="center" :edit-render="{ name: 'select', options: $opt.chargeOption }"></vxe-table-column>
                            <vxe-table-column field="test_dt" title="上机时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="test_username" title="上机用户 " width="106" header-align="center"></vxe-table-column>
                            <vxe-table-column field="report_dt" title="报告时间 " width="134" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="report_username" title="检验医生姓名 " width="92" header-align="center"></vxe-table-column>
                            <vxe-table-column field="rechk_username" title="核对医生姓名 " width="92" header-align="center"></vxe-table-column>
                            <vxe-table-column field="alter_flag" title="警告" width="82" header-align="center">
                                <template v-slot="{ row }">
                                    <div>{{ row.alter_flag == "0" ? "" : row.alter_flag == "1" ? "警" : "" }}</div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="saleman" title="所属销售人 " width="93" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_cardno" title="就诊卡号 " width="129" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_comm" title="医生备注 " width="197" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_birth" title="病人生日 " width="90" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="pat_ageyear" title="年龄岁数 " width="80" header-align="center"></vxe-table-column>
                            <vxe-table-column field="inp_id" title="住院标识 " width="76" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_diag_icd" title="诊断的ICD10编码 " width="121" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_address" title="病人联系地址 " width="145" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_nation" title="国家/民族 " width="94" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_idcardno" title="身份证号护照号 " width="142" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_phone" title="联系电话 " width="84" header-align="center"></vxe-table-column>
                            <vxe-table-column field="charge_typename" title="收费类型 " width="82" header-align="center"></vxe-table-column>
                            <vxe-table-column field="perform_deptname" title="执行科室 " width="90" header-align="center"></vxe-table-column>
                            <vxe-table-column field="original_reqno" title="原始单号 " width="90" header-align="center"></vxe-table-column>
                            <vxe-table-column field="secrecy" title="加密标志 " width="86" header-align="center"></vxe-table-column>
                            <vxe-table-column field="other_stat" title="备用标志 " width="86" header-align="center"></vxe-table-column>
                            <vxe-table-column field="cancel_dt" title="作废时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="cancel_username" title="作废用户 " width="75" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reject_count" title="退回次数 " width="70" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="specimen_code" title="标本类型 " width="74" header-align="center"></vxe-table-column>
                            <vxe-table-column field="sample_detail" title="标本备注说明 " width="101" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_reason" title="送检目的 " width="107" header-align="center"></vxe-table-column>
                            <vxe-table-column field="multi_seq" title="多条码序号 " width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_groupid" title="分单类别 " width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="report_id" title="报告单ID " width="81" header-align="center"></vxe-table-column>
                            <vxe-table-column field="report_user" title="检验医生 " width="81" header-align="center"></vxe-table-column>
                            <vxe-table-column field="rechk_user" title="核对医生 " width="80" header-align="center"></vxe-table-column>
                            <vxe-table-column field="recieve1_dt" title="工作组接收时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                            <vxe-table-column field="recieve1_username" title="工作组接收用户 " width="109" header-align="center"></vxe-table-column>
                            <vxe-table-column field="inlib_status" title="入库状态 " width="82" header-align="center"></vxe-table-column>
                            <vxe-table-column field="library_id" title="所在库位ID " width="82" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reqtype" title="业务类别 " width="88" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_height" title="身高 " width="65" header-align="center"></vxe-table-column>
                            <vxe-table-column field="weight" title="体重 " width="71" header-align="center"></vxe-table-column>
                            <vxe-table-column field="abo_bldtype" title="ABO血型 " width="90" header-align="center"></vxe-table-column>
                            <vxe-table-column field="rh_bldtype" title="RH血型 " width="94" header-align="center"></vxe-table-column>
                            <vxe-table-column field="hospcodename" title="送检医院 " width="133" header-align="center"></vxe-table-column>
                            <vxe-table-column field="recieve_host" title="检验科接收电脑 " width="125" header-align="center"></vxe-table-column>
                            <vxe-table-column field="rcvmsg" title="签收消息 " width="165" header-align="center"></vxe-table-column>

                            <vxe-table-column field="req_deptno" title="申请科室 " width="84" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_wardno" title="病人病区 " width="85" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_sex" title="性别 " width="50" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_stat" title="申请状态 " width="88" header-align="center"></vxe-table-column>
                            <vxe-table-column field="req_docno" title="申请医生 " width="75" header-align="center"></vxe-table-column>
                            <vxe-table-column field="pat_typecode" title="病人类型 " width="87" header-align="center"></vxe-table-column>
                            <vxe-table-column field="create_user" title="条码生成人 " width="84" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reject_user" title="退回用户 " width="80" header-align="center"></vxe-table-column>
                            <vxe-table-column field="print_user" title="打印用户 " width="81" header-align="center"></vxe-table-column>
                            <vxe-table-column field="sampled_user" title="采样用户 " width="83" header-align="center"></vxe-table-column>
                            <vxe-table-column field="send_user" title="送出护工 " width="83" header-align="center"></vxe-table-column>
                            <vxe-table-column field="recieve_user" title="检验科接收用户 " width="123" header-align="center"></vxe-table-column>
                            <vxe-table-column field="charge_user" title="计价人 " width="74" header-align="center"></vxe-table-column>
                            <vxe-table-column field="test_user" title="上机用户 " width="76" header-align="center"></vxe-table-column>
                            <vxe-table-column field="charge_typeno" title="收费类型 " width="72" header-align="center"></vxe-table-column>
                            <vxe-table-column field="perform_dept" title="执行科室 " width="73" header-align="center"></vxe-table-column>
                            <vxe-table-column field="cancel_user" title="作废用户 " width="75" header-align="center"></vxe-table-column>
                            <vxe-table-column field="report_user" title="检验医生 " width="71" header-align="center"></vxe-table-column>
                            <vxe-table-column field="rechk_user" title="核对医生 " width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="recieve1_user" title="工作组接收用户 " width="109" header-align="center"></vxe-table-column>
                            <vxe-table-column field="hospcode" title="送检医院 " width="123" header-align="center"></vxe-table-column>
                            <vxe-table-column field="cpperformdept" title="cpperformdept " width="109" header-align="center"></vxe-table-column>
                            <vxe-table-column field="cpperformlabgroup" title="cpperformlabgroup " width="123" header-align="center"></vxe-table-column>
                            <vxe-table-column field="packagebarcode" title="packagebarcode " width="123" header-align="center"></vxe-table-column>
                        </vxe-table>
                        <div class="table-bottom">
<div style="font-size: 17px; padding-top: 3px; background-color: #fff; text-align: center">
                                    <span style="font-weight: bold; color: red; margin-left: 35px">合计: {{ sumcnt }}</span>
                                </div>
                        </div>
                    </div>
                </rm-layout-right>
            </rm-layout-left>
        </div>

        <!--签收打包条码-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="签收打包条码" :visible.sync="dialogPackageRcv" width="1000px" :show-close="false">
            <rm-PackageBar-Rcv @cancel="packageCancel" :tableData1="packagedata" :remindtxt="remindstr" @appendDialog="appendDialog" :userinfoval="senduser" name="LIS222" @change="RetPackageChange" :trans="trans"></rm-PackageBar-Rcv>
        </el-dialog>
        <!--标本签收-->
        <el-dialog  v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="标本签收" :visible.sync="dialogSpecimenRcv" width="1000px" :show-close="false">
            <rm-Specimen-Rcv :tableData2="specimenData" @cancel="specimenCancel" :userinfoval="senduser" :packagebarcode="packagebarcode" name="LIS222" @change="RetSpecimenChange" :key="specimenkey" ></rm-Specimen-Rcv>
        </el-dialog>

        <!-- <div style="width:100px;height:15px;position:absolute;left:100px;bottom:16px;color:blue;font-size:12px">标本总数：{{samplecnt}}</div> -->

        <el-dialog ref="edialog01" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="提示" :visible.sync="diagPromiseVisible1">
            <div v-for="msg in msglist" :key="msg.title" style="over-flow: auto">
                <h3 style="color: red">{{ msg.Item1 }}</h3>
                <h5 v-html="msg.Item2"></h5>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="diagPromise_click(-1)">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog ref="edialog02" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="提示" :visible.sync="diagPromiseVisible2">
            <div v-for="msg in msglist" :key="msg.title" style="over-flow: auto">
                <h3 style="color: red">{{ msg.Item1 }}</h3>
                <h5 v-html="msg.Item2"></h5>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="diagPromise_click(1)">是</el-button>
                <el-button @click="diagPromise_click(0)">否</el-button>
            </span>
        </el-dialog>

        <!--选项设置弹窗-->
        <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="LIS222标本流转打包" :visible.sync="dialogSetting" width="650px">
            <div style="height: 450px">
                <rm_GeneralOptions_page URL="MNG/MNG1/MNG137" SQLKEY="PRG" OptionClass="本地" :isdialog="true" checkOne="LIS222"></rm_GeneralOptions_page>
            </div>
        </el-dialog>

        <el-dialog width="1050px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="包条码清单" :visible.sync="dialogHistoryTableVisible">
            <template>
                <div style="width: 100%; position: relative">
                    <div style="height: 40px; width: 100%">
                        <table style="font-size: 12px; white-space: nowrap; max-width: 1170px">
                            <tr>
                                <td>创建时间</td>
                                <td style="width: 140px">
                                    <el-date-picker v-model="startdt" :able="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%; min-width: 100px" :picker-options="pickerOptions" :clearable="false" :key="startkey"> </el-date-picker>
                                </td>
                                <td align="center">至</td>
                                <td style="width: 140px">
                                    <el-date-picker v-model="enddt" type="date" :able="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%; min-width: 100px" :picker-options="pickerOptions" :clearable="false" :key="endkey"> </el-date-picker>
                                </td>
                                <td style="width: 60px; text-align: right">创建人</td>
                                <td>
                                    <rm-ddl-common datatype="userinfo" dataname="用户" v-model="create_user" width="150px"></rm-ddl-common>
                                </td>
                                <td style="width: 70px; text-align: right">接收工作组</td>
                                <td style="width: 140px">
                                    <rm-ddl-common datatype="labgroup" dataname="检验工作组" v-model="pagrcvdept" width="140px" key="5"></rm-ddl-common>
                                </td>
                                <td style="width: 100px; text-align: right">
                                    <el-button @click="btnHistoryQuery()" icon="el-icon-search">查询</el-button>
                                    <!-- <el-button @click="btnHistoryPrint()" icon="el-icon-printer">打印包条码</el-button> -->
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div style="height: 400px; top: 60px; width: 100%">
                        <vxe-table :data.sync="historytableData" :loading="historyloading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row class="mytablestyle" highlight-hover-column ref="hTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe @dblclick.native="loginbarcodes()">
                            <!-- <vxe-table-column type="selection" width="40" align="center"></vxe-table-column> -->
                            <vxe-table-column align="center" type="index" title="序号" width="40"></vxe-table-column>
                            <vxe-table-column field="packagebarcode" sortable title="传送条码" width="100"></vxe-table-column>
                            <vxe-table-column field="samplecount" sortable title="标本数量" width="65"></vxe-table-column>
                            <vxe-table-column field="createusername" sortable title="创建人" width="60"></vxe-table-column>
                            <vxe-table-column field="createtime" sortable title="创建时间" width="120"></vxe-table-column>
                            <vxe-table-column field="sendusername" sortable title="送出人" width="60"></vxe-table-column>
                            <vxe-table-column field="senddeptname" sortable title="送出部门" width="80"></vxe-table-column>
                            <vxe-table-column field="sendlabgroupname" sortable title="送出工作组" width="80"></vxe-table-column>
                            <vxe-table-column field="recieveusername" sortable title="接收人" width="80"></vxe-table-column>
                            <vxe-table-column field="recievedeptname" sortable title="接收部门" width="80"></vxe-table-column>
                            <vxe-table-column field="reclabgroupname" sortable title="接收工作组" width="80"></vxe-table-column>
                            <vxe-table-column field="transtime" sortable title="交接时间" width="120"></vxe-table-column>
                            <vxe-table-column field="statusname" sortable title="状态" width="60"></vxe-table-column>
                        </vxe-table>
                    </div>
                </div> </template
        ></el-dialog>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
    name: "LIS222",
    data() {
        return {
            dialogSetting: false,
            packagebarcode: "",
            ShowLeft: "1",
            LeftWidth: 300,
            leftsplit: 5,
            hidkey: 0,
            leftloading: false,
            senduser: this.$tool.getSession(this.$tool.loginuserno),
            userno: this.$tool.getSession(this.$tool.loginuserno),
            senddept: "",
            rcvdept: "",
            txtbarcode: "",
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            diagPromiseVisible1: false,
            diagPromiseVisible2: false,
            msglist: [],
            dialogPackageRcv: false,
            dialogSpecimenRcv: false,
            specimenData: [],
            packagedata: [],
            master: [],
            detail: [],
            remindstr: "",
            buttonwidth: 0,
            barcodearrivemode: "",
            transtype: "",
            senddept: "",
            labgroupid: "",
            leftrowclick: "",
            packagebarcode: "",
            reBarcodeMsgList: [],
            packbarStyleid: "5015",
            CircStyleid: "5008",
            deptoption: [],
            groupoption: [],
            trans: "",
            dialogHistoryTableVisible: false, // 历史记录弹出
            pickerOptions: {
                shortcuts: [
                    {
                        text: "今天",
                        onClick(picker) {
                            picker.$emit("pick", new Date());
                            _that.sample_startdt = new Date();
                            _that.sample_enddt = new Date();
                        },
                    },
                ],
            },
            startdt: this.$pub.InitDateTime2(0).datefrom,
            enddt: this.$pub.InitDateTime2(0).dateto,
            startkey: 0,
            endkey: 0,
            historytableData: [],
            create_user: "",
            pagrcvdept: "",
            historyloading: false,
            isnoprintpackagebarcodet: "", // 不打印包条码  0 打印 1 不打印
            issend: false,
            isshowsend: true,
            isshowrecive: true,
            receivesendmode: "",
            hidpackbarcode: "",
            isused: false,
            rcv_dupnomsgbox: "",
            rcv_dupnomsgbox: "",
            handovershowlogin:"",
            specimenkey:0,
            printData:[],
        };
    },
    created() {
        //this.InitPageDate(); //初始化主列表
        this.getoption();
    },
    computed: {
        list() {
            //这个列表的显示关键通过获取master
            if (!!this.master && this.master.length > 0) {
                let data = this.group(this.master, this.transtype, function (item) {
                    return item.cpperformlabgroup + "," + item.cpperformdept;
                });
                return data;
            }
        },
        masterList() {
            if (this.leftrowclick != "" && !!this.master) {
                //是行选中状态
                return this.master.filter((item) => item.cpperformlabgroup == this.leftrowclick.reclabgroupid && item.cpperformdept == this.leftrowclick.receivedept);
            } else {
                return this.master;
            }
        },
        samplecnt() {
            //标本总数
            if (!!this.list) {
                return XEUtils.sum(this.list, "samplecount");
            } else {
                return 0;
            }
        },
        sumcnt() {
            //合计
            if (this.master.length > 0) {
                let data = this.$refs.xTable1.tableData;
                return data.length;
            } else {
                return 0;
            }
        },
    },
    updated() {
        this.getButtonWidth();
    },
    mounted() {
        this.$refs.barcode.focus();
    },
    updated() {},
    methods: {
        getButtonWidth() {
            if (this.$refs.buttondiv) {
                this.buttonwidth = this.$refs.buttondiv.offsetWidth - 200 + "px";
            }
        },
        getoption() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "getoptions",
                    },
                })
                .then((res) => {
                    this.barcodearrivemode = res.barcodearrivemode;
                    this.transtype = res.transtype;
                    this.ShowLeft = !res.autorecdept ? "0" : res.autorecdept; //默认为0
                    this.packbarStyleid = res.packbarStyleid;
                    this.CircStyleid = res.CircStyleid;
                    this.deptoption = res.deptoption;
                    this.groupoption = res.groupoption;
                    this.isnoprintpackagebarcodet = res.isnoprintpackagebarcodet;
                    this.handovershowlogin = res.handovershowlogin;
                    if (res.transtype == "3") {
                        //科内移交
                        this.senddept = res.labgroupid;
                    } else if (res.transtype == "5") {
                        //院区流转
                        this.senddept = res.hospcode;
                        this.ShowLeft = "0"; //这里临时加上，暂时院区流转不支持自动识别接收部门，支持后去掉
                        this.$alert("院区流转暂时不支持自动识别接收部门功能！", "提示");
                    } else {
                        this.senddept = res.senddept;
                    }
                    this.receivesendmode = res.receivesendmode;
                    if (res.receivesendmode == "1") {
                        this.isshowsend = false;
                        this.isshowrecive = true;
                    } else if (res.receivesendmode == "2") {
                        this.isshowsend = true;
                        this.isshowrecive = false;
                    } else {
                        this.isshowsend = true;
                        this.isshowrecive = true;
                    }
                    this.rcv_dupnomsgbox = res.rcv_dupnomsgbox;
                    this.rcv_showinvalid = res.rcv_showinvalid;

                    this.left_show_hide();
                })
                .catch((e) => {
                    console.log("error", e);
                });
        },
        //控制左边显示或隐藏
        left_show_hide() {
            if (this.ShowLeft == "0") {
                this.LeftWidth = 0;
                this.leftsplit = 0;
            } else {
                this.LeftWidth = 350;
                this.leftsplit = 5;
            }
            this.hidkey++;
        },
        group(list, transtype, f) {
            //分组函数
            const groups = {};
            list.forEach(function (re) {
                const group = f(re);
                groups[group] = groups[group] || [];
                groups[group].push(re);
            });

            return Object.keys(groups).map(function (group) {
                let groupLabel = group.split(","); //根据“，”切割成数组（可自定义）
                return {
                    reclabgroupid: groupLabel[0], //接收部门cpperformdept
                    receivedept: groupLabel[1], //接收工作组cpperformlabgroup
                    samplecount: groups[group].length, //标本数
                    status: "初始",
                    transtype: transtype,
                    packagebarcode: groups[group][groups[group].length - 1].packagebarcode,
                    lastbarcode: groups[group][groups[group].length - 1].lastbarcode,
                    lastpatname: groups[group][groups[group].length - 1].lastpatname,
                };
            });
        },
        diagPromise_click(t) {
            if (t == 0) {
                //点了取消按钮
                this.$refs.edialog02.Cancel();
            } else if (t == 1) {
                //点了确定按钮
                this.$refs.edialog02.Confirm();
            } else {
                this.$refs.edialog01.Confirm();
            }
        },
        leftChangeEvent({ row }) {
            this.exeLeftChangeEvent(row);
        },
        exeLeftChangeEvent(row) {
            this.leftrowclick = row;
        },
        //清除
        btnClear() {
            if (this.ShowLeft == "1") {
                //自动识别接收部门时
                let delrow = this.$refs.leftxTable.getCurrentRow();
                if (delrow) {
                    if (!delrow.packagebarcode) {
                        //条码未送出
                        this.msglist = [{ Item1: "所选条码尚未送出，您确定要清除吗？", Item2: "" }];
                        this.rcvmsgfault(1, "", "")
                            .then(() => {
                                this.confirmClear(delrow);
                            })
                            .catch(() => {
                                this.$message.warning("已取消删除！");
                                this.autoFocusBarcode();
                            });
                    } else {
                        this.confirmClear(delrow);
                    }
                }
            } else {
                this.txtbarcode = "";
                this.master = [];
                this.detail = [];
                this.packagebarcode = "";
                this.rcvdept = "";
            }
            this.$refs.barcode.focus();
            this.isused = false;
            this.hidpackbarcode = "";
            this.autoFocusBarcode();
        },
        //全部清除
        btnClearAll(){
            if (this.ShowLeft == "1") {
                //自动识别接收部门时
                this.txtbarcode = "";
                this.list = [];
                this.detail = [];
                this.masterList = [];
                this.master = [];
                this.packagebarcode = "";
            } else {
                this.txtbarcode = "";
                this.master = [];
                this.detail = [];
                this.packagebarcode = "";
                this.rcvdept = "";
            }
            this.$refs.barcode.focus();
            this.isused = false;
            this.hidpackbarcode = "";
            this.autoFocusBarcode();
        },
        confirmClear(delrow) {
            if (delrow) {
                let rowindex = this.list.indexOf(delrow);
                new Promise((resolve) => {
                    this.clearCenter();
                    resolve();
                }).then(() => {
                    if (!!this.list && this.list.length > 0) {
                        if (rowindex >= this.list.length) rowindex = this.list.length - 1;
                        let selectrow = this.list[rowindex];
                        this.$refs.leftxTable.setCurrentRow(selectrow);
                        this.exeLeftChangeEvent(selectrow);
                        this.RowSetHightlight(false);
                        this.autoFocusBarcode();
                    }
                });
            } else {
                this.$alert("请选中要清除的数据！");
            }
            this.autoFocusBarcode();
        },
        clearCenter() {
            let object = this.$refs.xTable1.tableData;
            for (const delrow of object) {
                var alld = this.master;
                var rowindex = alld.indexOf(delrow);
                this.master.splice(rowindex, 1);
                let havedata = this.master;
                if (!!havedata && havedata.length > 0) {
                    if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                    let selectrow = havedata[rowindex];
                    this.$refs.xTable1.setCurrentRow(selectrow);
                    this.Exedetailretrieve(selectrow);
                } else {
                    this.detail = [];
                }
            }
        },
        //删除
        btnDelete() {
            try {
                var delrow = this.$refs.xTable1.getCurrentRow();
                if (delrow) {
                    var alld = this.master;
                    var rowindex = alld.indexOf(delrow);
                    this.master.splice(rowindex, 1);
                    let havedata = this.master;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.xTable1.setCurrentRow(selectrow);
                        this.Exedetailretrieve(selectrow);
                    } else {
                        this.detail = [];
                    }
                }
                this.autoFocusBarcode();
            } catch (e) {
                console.log("error", e);
                this.autoFocusBarcode();
            }
        },
        formatFun({ row, column, cellValue }) {
            if (column.property == "receivedept") {
                return this.getName(cellValue, "receivedept");
            } else if (column.property == "reclabgroupid") {
                return this.getName(cellValue, "reclabgroupid");
            } else {
                return cellValue;
            }
        },
        getName(cellValue, column) {
            if (column == "receivedept") {
                let k1 = this.deptoption.find((m) => m.data == cellValue);
                if (k1 != undefined) {
                    return k1.display;
                } else {
                    return cellValue;
                }
            } else {
                let k2 = this.groupoption.find((m) => m.data == cellValue);
                if (k2 != undefined) {
                    return k2.display;
                } else {
                    return cellValue;
                }
            }
        },
        userinfochange(code, name) {
            this.senduser = code;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "userinfoChange",
                        transtype: this.transtype,
                        senduser: code,
                    },
                })
                .then((res) => {
                    this.senddept = res.data;
                })
                .catch((e) => {
                    this.$alert("错误：" + e, "提示");
                });
        },
        senddeptchange() {},
        rcvdeptchange() {},
        autoFocusBarcode(){
            setTimeout(() => {
                this.FocusBarcode(); //聚焦到条码框
            }, 100);
        },
        //聚焦条码框
        FocusBarcode(myField) {
            if (!myField) myField = document.getElementById("barcodediv");
            myField.focus();
            myField.select();
        },
        HightlightPos(myValue) {
            if (myValue == "") {
                return false;
            }
            var myField = document.getElementById("barcodediv");
            if (myField.selectionStart || myField.selectionStart === 0) {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                this.$nextTick(() => {
                    myField.selectionStart = 0;
                    myField.selectionEnd = startPos + myValue.length;
                }); // 这句是重点, 圈起来
                myField.focus();
                myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
            }
        },
        detailretrieve({ row }) {
            this.Exedetailretrieve(row);
            this.HightlightPos(this.txtbarcode);
        },
        async Exedetailretrieve(row) {
            try {
                var barcode = row.barcode;
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS212",
                    method: "post",
                    data: {
                        action: "getdetails",
                        barcode: barcode,
                    },
                });
                this.detail = res.details;
                if (res.details.length > 0) {
                    this.$refs.xTable2.setCurrentRow(res.details[0]);
                }
                this.autoFocusBarcode();
            } catch (e) {
                console.log("error", e);
                this.autoFocusBarcode();
            }
        },
        //单组送出，此时ShowLeft=1，只有自动识别接收部门有
        async rowclick(row) {
            if (!this.senddept) {
                this.$alert("请先选择送出部门！", "提示", {
                    confirmButtonText: "确定",
                });
                return false;
            }
            let barcodes = "";
            let data = [];
            if (this.transtype == "3") {
                data = this.master.filter((item) => item.cpperformlabgroup == row.reclabgroupid);
            } else {
                data = this.master.filter((item) => item.cpperformdept == row.receivedept);
            }
            if (data.length > 0) {
                data.forEach((item) => {
                    if (barcodes == "") {
                        barcodes = item.barcode;
                    } else {
                        barcodes = barcodes + "," + item.barcode;
                    }
                });
            } else {
                this.$alert("读取数据出错，请检查部门科室或检验工作组是否已取值！");
                return false;
            }
            //开始送出
            let res = await this.sendout(barcodes, row.reclabgroupid, row.receivedept);
            if (res.flag == "1") {
                //送出成功时消息即为条码号
                row.packagebarcode = res.msg;
                data.forEach((item) => {
                    item.packagebarcode = res.msg;
                });
                // this.packagebarcode = res.msg;
                this.$alert("送出成功！是否清除当前送出的条码？", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    showCancelButton: true,
                }).then(() => {
                        //清除当前送出的包条码
                        var delrow = this.$refs.leftxTable.tableFullData.find((m) => m.packagebarcode == row.packagebarcode);//重新查找一下当前行，赋值之后，表格的rowid已经变了
                        if (delrow) {
                            this.confirmClear(delrow);
                        }
                        this.$refs.barcode.focus();
                        this.isused = false;
                        this.hidpackbarcode = "";
                        this.autoFocusBarcode();
                    })
                    .catch(() => {
                    });
                if (this.isnoprintpackagebarcodet == "0") {
                    await this.sendoutPrint(row);
                }
            } else {
                let msg1 = "送出失败！";
                this.msglist = this.msginfoList(res.msg, msg1);
                await this.rcvmsgfault(-1, "", "");
            }
        },
        async btnSend() {
            //全部送出
            if (!this.senduser) {
                this.$alert("请先选择送出人！", "提示", {
                    confirmButtonText: "确定",
                });
                return false;
            }
            if (!this.senddept) {
                this.$alert("请先选择送出部门！", "提示", {
                    confirmButtonText: "确定",
                });
                return false;
            }
            if (!this.rcvdept && this.ShowLeft != "1") {
                //不自动识别接收部门并且没有勾选接收部门
                this.$confirm("接收部门为空，你确定要不指定接受部门吗？", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    focusCancelButton: true,
                    type: "warning",
                })
                    .then(() => {
                        this.strartSend();
                    })
                    .catch(() => {
                        this.autoFocusBarcode();
                    });
            } else {
                this.strartSend();
            }
            this.autoFocusBarcode();
        },
        //准备送出
        async strartSend() {
            this.issend = true;
            if (this.ShowLeft == "1") {
                //自动识别接收部门，左边显示，页面无接收部门，从表格取
                let object = this.list.filter((item) => !item.packagebarcode); //找出没有包条码号的
                if (object.length > 0) {
                    //如果存在未打包的
                    if (this.transtype == "3") {
                        for (const row of object) {
                            let barcodes1 = "";
                            let labgroupdata = this.master.filter((item) => item.cpperformlabgroup == row.reclabgroupid);
                            if (labgroupdata.length > 0) {
                                labgroupdata.forEach((item) => {
                                    barcodes1 += item.barcode + ",";
                                });
                                barcodes1 = barcodes1.substring(0, barcodes1.length - 1);
                            } else {
                                this.$alert("读取数据出错，请检查部门科室是否已取值！");
                                return false;
                            }

                            let sendret1 = await this.sendout(barcodes1, row.reclabgroupid, ""); //组内送出消息返回
                            if (sendret1.flag == "1") {
                                //送出成功,返回包条码号,即msg
                                row.packagebarcode = sendret1.msg;
                                labgroupdata.forEach((item) => {
                                    item.packagebarcode = sendret1.msg;
                                });
                            } else {
                                //送出失败，弹出失败消息
                                //await this.$alert(sendret.msg);
                                let msg1 = "送出失败！";
                                this.msglist = this.msginfoList(sendret1.msg, msg1);
                                await this.rcvmsgfault(-1, "", "");
                            }
                        }
                        if (this.isnoprintpackagebarcodet == "0") {
                            await this.sendoutPrint("All");
                        } else {
                            // this.master = [];
                            // this.detail = [];
                            // this.packagebarcode = "";
                            // this.rcvdept = "";
                            // this.txtbarcode = "";
                            // this.$refs.barcode.focus();
                            // this.hidpackbarcode = "";
                        }
                    } else {
                        for (const row of object) {
                            let barcodes2 = "";
                            let deptdata = this.master.filter((item) => item.cpperformdept == row.receivedept); //部门科室送出消息返回
                            if (deptdata.length > 0) {
                                deptdata.forEach((item) => {
                                    barcodes2 += item.barcode + ",";
                                });
                                barcodes2 = barcodes2.substring(0, barcodes2.length - 1);
                            } else {
                                this.$alert("读取数据出错，请检查部门科室是否已取值！");
                                return false;
                            }
                            let sendret2 = await this.sendout(barcodes2, "", row.receivedept);
                            if (sendret2.flag == "1") {
                                //送出成功,返回包条码号,应该还会返回一个列表赋值Req_Trans
                                row.packagebarcode = sendret2.msg;
                                deptdata.forEach((item) => {
                                    item.packagebarcode = sendret2.msg;
                                });

                                //this.$alert("送出成功！","提示");
                            } else {
                                //送出失败
                                //await  this.$alert(sendret.msg);
                                let msg2 = "送出失败！";
                                this.msglist = this.msginfoList(sendret2.msg, msg2);
                                await this.rcvmsgfault(-1, "", "");
                            }
                        }
                        if (this.isnoprintpackagebarcodet == "0") {
                            await this.sendoutPrint("All");
                        } else {
                            // this.master = [];
                            // this.detail = [];
                            // this.packagebarcode = "";
                            // this.rcvdept = "";
                            // this.txtbarcode = "";
                            // this.$refs.barcode.focus();
                            // this.hidpackbarcode = "";
                        }
                    }
                } else {
                    //标本已经全部打包
                    if (this.isnoprintpackagebarcodet == "0") {
                        await this.sendoutPrint("All");
                    } else {
                        // this.master = [];
                        // this.detail = [];
                        // this.packagebarcode = "";
                        // this.rcvdept = "";
                        // this.txtbarcode = "";
                        // this.$refs.barcode.focus();
                        // this.hidpackbarcode = "";
                    }
                }
            } else {
                //不自动识别接收部门，左边不显示，页面有接收部门，从顶部条件取
                if (this.master.length == 0) return false;
                let barcodes = "";
                this.master.forEach((item) => {
                    if (barcodes == "") {
                        barcodes = item.barcode;
                    } else {
                        barcodes = barcodes + "," + item.barcode;
                    }
                });
                let sendret3 = await this.sendout(barcodes, this.rcvdept, this.rcvdept);
                if (sendret3.flag == "1") {
                    this.$alert("送出成功！", "提示", {
                        confirmButtonText: "确定",
                    });
                    //后台要返回我packagebarcode,暂时注释
                    this.master.forEach((item) => {
                        item.packagebarcode = sendret3.msg;
                    });
                    //整个页面的数据打包为一个条码
                    this.packagebarcode = sendret3.msg;
                    this.hidpackbarcode = sendret3.msg;
                    if (this.isnoprintpackagebarcodet == "0") {
                        await this.sendoutPrint();
                    } else {
                        // this.master = [];
                        // this.detail = [];
                        // this.packagebarcode = "";
                        // this.rcvdept = "";
                        // this.txtbarcode = "";
                        // this.$refs.barcode.focus();
                        // this.hidpackbarcode = "";
                    }
                } else {
                    let msga = "送出失败！";
                    this.msglist = this.msginfoList(sendret3.msg, msga);
                    await this.rcvmsgfault(-1, "", "");
                }
            }
            this.issend = false;
            this.autoFocusBarcode();
        },
        //开始送出
        async sendout(barcodes, reclabgroup, recdept) {
            const res = await this.$tool.request({
                url: "LIS/LIS2/LIS222",
                method: "post",
                data: {
                    action: "sendout",
                    barcode: barcodes,
                    senddept: this.senddept,
                    senduser: this.senduser,
                    reclabgroup: reclabgroup,
                    recdept: recdept,
                    packbarcode: this.hidpackbarcode,
                },
            });
            return res;
        },
        //送出成功后,弹窗是否打印包条码
        async sendoutPrint(row) {
            if (typeof jsObj != "undefined") {
                this.$confirm("送出成功，是否打印包条码？", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    focusCancelButton: true,
                    type: "warning",
                })
                    .then(() => {
                        this.btnPrintBarcode(row);
                    })
                    .catch(() => {
                        this.autoFocusBarcode();
                    });
            } else {
                that.$alert("请使用" + this.$pub.clientname + "打开系统", "错误", {
                    confirmButtonText: "确定",
                });
            }
        },
        // 打印包条码
        async btnPrintBarcode(row) {
            let barcode = "";
            if (!this.packbarStyleid) {
                this.$alert("请在检验本地选项中设置包条码格式！");
                return false;
            }
            if (this.ShowLeft == "1") {
                //自动识别接收部门

                let object = [];
                if (row == "All") {
                    //所有送出,找到没有送出的，然后打印没有送出的
                    object = this.list.filter((item) => !!item.packagebarcode);
                } else {
                    //单组送出，只送出选中的那一组
                    object.push(row);
                }

                //左边找出存在packagebarcode的数据
                if (object.length > 0) {
                    const rLoading = this.openLoading("正在打印包条码……");
                    for (const item of object) {
                        let data = await this.getSonBarcodes(item.packagebarcode);
                        //this.master.filter(m => m.packagebarcode == item.packagebarcode);
                        if (data.sum > 0) {
                            let receivedeptname = this.getName(item.receivedept, "receivedept");
                            let reclabgroupname = this.getName(item.reclabgroupid, "reclabgroupid");
                            if (this.transtype == "3") {
                                //科内移交（接收部门即为检验工作组）
                                receivedeptname = reclabgroupname;
                            } else {
                                //反之检验工作组即为接收部门
                                reclabgroupname = receivedeptname;
                            }
                            var packagebarcode = item.packagebarcode;
                            let sql= "select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门, RecLabGroupID as 接收工作组, bb.deptname as 送出部门,cc.allcomcount as 单采标本数,cc.allmixcount as 混检标本数,u.username as 创建者, comments as 备注,'' as 采样点 from Req_Trans left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno left join (select '" + packagebarcode.trim() + "' as packagebrc,count(*) as allcount, sum(mixcount) as allmixcount, (count(*) - sum(mixcount)) as allcomcount from (select a.packagebarcode, (case when isnull(b.mixbarcode, '') = '' then 0 else 1 end) as mixcount from req_transdetail as a left join req_mixsample b on a.barcode = b.mixbarcode where PackageBarcode = '" + packagebarcode.trim() + "') c) cc on Req_Trans.packagebarcode = cc.packagebrc where Req_Trans.PackageBarcode = '" + packagebarcode.trim() + "'";
                            this.$pub.printlistbill(this, sql, "1", this.packbarStyleid, "打印包条码", "");
                            this.autoFocusBarcode();
                        }
                    }
                    rLoading.close();
                } else {
                    this.$alert("未检测到有送出的条码，不能打印！");
                    return false;
                }
                this.autoFocusBarcode();
            } else {
                //不自动识别接收部门
                if (this.packagebarcode != "") {
                    let data = await this.getSonBarcodes(this.packagebarcode); //this.master.length;
                    if (data.sum > 0) {
                        const rLoading = this.openLoading("正在打印包条码……");
                        var packagebarcode = this.packagebarcode;
                        let sql= "select SampleCount as 标本数量, SendUser as 送出人, CONVERT(varchar,GETDATE(),120) as 打印时间,  PackageBarcode as 包条码号,  dc_dept.deptname as 接收部门, RecLabGroupID as 接收工作组, bb.deptname as 送出部门,cc.allcomcount as 单采标本数,cc.allmixcount as 混检标本数,u.username as 创建者, comments as 备注,'' as 采样点 from Req_Trans left join dc_dept on Req_Trans.RecieveDept = dc_dept.deptno left join dc_dept bb on Req_Trans.senddept = bb.deptno left join secsysuser u on Req_Trans.createuser = u.userno left join (select '" + packagebarcode.trim() + "' as packagebrc,count(*) as allcount, sum(mixcount) as allmixcount, (count(*) - sum(mixcount)) as allcomcount from (select a.packagebarcode, (case when isnull(b.mixbarcode, '') = '' then 0 else 1 end) as mixcount from req_transdetail as a left join req_mixsample b on a.barcode = b.mixbarcode where PackageBarcode = '" + packagebarcode.trim() + "') c) cc on Req_Trans.packagebarcode = cc.packagebrc where Req_Trans.PackageBarcode = '" + packagebarcode.trim() + "'";
                        this.$pub.printlistbill(this, sql, "1", this.packbarStyleid, "打印包条码", "");
                        rLoading.close();
                        this.autoFocusBarcode();
                    }
                    // 打印完，清除页面数据
                    // this.master = [];
                    // this.detail = [];
                    // this.packagebarcode = "";
                    // this.rcvdept = "";
                    // this.$refs.barcode.focus();
                    // this.hidpackbarcode = "";
                } else {
                    this.$alert("未检测到有送出的条码，不能打印！");
                    return false;
                }
            }
        },
        openLoading(loadtxt) {
            const loading = this.$loading({
                // 声明一个loading对象
                lock: true, // 是否锁屏
                text: loadtxt, // 加载动画的文字
                spinner: "el-icon-loading", // 引入的loading图标
                background: "rgba(0, 0, 0, 0.3)", // 背景颜色
                target: ".sub-main", // 需要遮罩的区域
                body: true,
                customClass: "mask", // 遮罩层新增类名
            });
            setTimeout(function () {
                // 设定定时器，超时5S后自动关闭遮罩层，避免请求失败时，遮罩层一直存在的问题
                loading.close(); // 关闭遮罩层
            }, 5000);
            return loading;
        },
        //打印清单
        async btnPrintList(e) {
            if (e.shiftKey) {
                //调整
                // let sql= "select e.username as 送出人 ,f.username as 接收者,g.deptname as 接收部门,h.labgroupname as 接收工作组,c.* from (select top 1 1 as 条数,'2' as 交接批号,* from req_master_all_name ) c left join req_trans d on d.packagebarcode= 交接批号 left join secsysuser e on d.senduser =e.userno left join secsysuser f on d.recieveuser =f.userno left join dc_dept g on d.recievedept = g.deptno left join dc_labgroup h on d.reclabgroupid = h.labgroupid ";
                // this.$pub.printlistbill(this, sql, "3", this.CircStyleid, "流转清单样式", "");

                let res = await this.getPrintData('3','1','2','');
                console.info(res);
                const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                let column =  res.RData.Cols;
                var tableColumn = [];
                for(let i = 0;i < column.length;i++)
                {
                    let item = column[i];
                    tableColumn.push({
                        title: item.title,
                        property: item.field
                    });
                }
                let str = JSON.stringify(tableColumn);
                str += "\r";
                str += JSON.stringify(res.RData.Data);
                console.info(str);
                let sql = btoa(encodeURIComponent(str));
                jsObj.SetCustomJsonPrintConfig(this.CircStyleid, sql, this.$tool.getSession(this.$tool.loginuserno), "流转清单样式");
                rload.close();
            } else {
                //打印
                if (this.ShowLeft == "1") {
                    //自动识别接收部门
                    let object = this.list.filter((item) => item.packagebarcode != null);
                    //左边找出存在packagebarcode的数据
                    if (object.length > 0) {
                        const rLoading = this.openLoading("正在打印流转清单……");
                        for (const item of object) {
                            let data = await this.getSonBarcodes(item.packagebarcode);
                             // if (data.sum > 0) {
                            //     let sql= "select e.username as 送出人 ,f.username as 接收者,g.deptname as 接收部门,h.labgroupname as 接收工作组,c.* from (select '" + data.sum + "' as 条数,'" + item.packagebarcode + "' as 交接批号,* from req_master_all_name where 条码号 in ('" + data.barcodes + "') ) c left join req_trans d on d.packagebarcode= 交接批号 left join secsysuser e on d.senduser =e.userno left join secsysuser f on d.recieveuser =f.userno left join dc_dept g on d.recievedept = g.deptno left join dc_labgroup h on d.reclabgroupid = h.labgroupid ";
                            //     this.$pub.printlistbill(this, sql, "1", this.CircStyleid, "流转清单样式", "");
                            // }
                            if(data.sum > 0){
                                let res = await this.getPrintData('1', data.sum,item.packagebarcode,data.barcodes);
                                if (res.RData.Data.length > 0) {
                                    let column = res.RData.Cols;
                                    var tableColumn = [];
                                    for(let i = 0;i < column.length;i++)
                                    {
                                        let item = column[i];
                                        tableColumn.push({
                                            title: item.title,
                                            property: item.field
                                        });
                                    }
                                    let str = JSON.stringify(tableColumn);
                                    str += "\r";
                                    str += JSON.stringify(res.RData.Data);
                                    let sql = btoa(encodeURIComponent(str));
                                    jsObj.PrintCustomJsonReport(this.CircStyleid, sql, this.$tool.getSession(this.$tool.loginuserno), "流转清单样式", "");
                                } else {
                                    this.$message.error("错误：没有要打印的数据！");
                                }
                            }
                        }
                        rLoading.close();
                    } else {
                        this.$alert("未检测到有送出的条码，不能打印！");
                        return false;
                    }
                } else {
                    //不自动识别接收部门
                    let data = await this.getSonBarcodes(this.packagebarcode);
                    if (data.sum > 0) {
                        // let sql= "select e.username as 送出人 ,f.username as 接收者,g.deptname as 接收部门,h.labgroupname as 接收工作组,c.* from (select '" + data.sum + "' as 条数,'" + this.packagebarcode + "' as 交接批号,* from req_master_all_name where 条码号 in ('" + data.barcodes + "') ) c left join req_trans d on d.packagebarcode= 交接批号 left join secsysuser e on d.senduser =e.userno left join secsysuser f on d.recieveuser =f.userno left join dc_dept g on d.recievedept = g.deptno left join dc_labgroup h on d.reclabgroupid = h.labgroupid";
                        // this.$pub.printlistbill(this, sql, "1", this.CircStyleid, "流转清单样式", "");
                        let res = await this.getPrintData('1', data.sum,data.packagebarcode,data.barcodes);
                        if (res.RData.Data.length > 0) {
                            let column = res.RData.Cols;
                            var tableColumn = [];
                            for(let i = 0;i < column.length;i++)
                            {
                                let item = column[i];
                                tableColumn.push({
                                    title: item.title,
                                    property: item.field
                                });
                            }
                            let str = JSON.stringify(tableColumn);
                            str += "\r";
                            str += JSON.stringify(res.RData.Data);
                            let sql = btoa(encodeURIComponent(str));
                            jsObj.PrintCustomJsonReport(this.CircStyleid, sql, this.$tool.getSession(this.$tool.loginuserno), "流转清单样式", "");
                        } else {
                            this.$message.error("错误：没有要打印的数据！");
                        }
                    } else {
                        this.$alert("条码未送出，不能打印", "提示");
                    }
                }
            }
        },
        async getPrintData(type,cnt,packagebarcode,barcodes) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "getPrintData",
                        type: type,
                        cnt: cnt,
                        packagebarcode: packagebarcode,
                        barcodes: barcodes,
                    },
                });
                return res;
            } catch (e) {
                this.$alert(e);
            }
        },

        async RowPrintList({ row }) {
            let str = "";
            //console.log(row.reclabgroupid);
            if (this.transtype == "3") {
                str = "是否仅打印送到[" + this.getName(row.reclabgroupid, "reclabgroupid") + "]的标本清单";
            } else {
                str = "是否仅打印送到[" + this.getName(row.receivedept, "receivedept") + "]的标本清单";
            }
            this.$confirm(str, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                focusCancelButton: true,
                type: "warning",
            })
                .then(() => {
                    if (!!row.packagebarcode) {
                        const rLoading = this.openLoading("正在打印流转清单……");
                        let data = async () => await this.getSonBarcodes(row.packagebarcode);
                        data().then((data) => {
                            if (data.sum > 0) {
                                // let sql = "select '" + data.sum + "' as 条数,'" + row.packagebarcode + "' as 交接批号,* from req_master_all_name where 条码号 in ('" + data.barcodes + "')";
                                // this.$pub.printlistbill(this, sql, "1", this.CircStyleid, "流转清单样式", "");
                                let res = async () => await this.getPrintData('1', data.sum,data.packagebarcode,data.barcodes);
                                res().then((rtndata) =>{
                                    if (rtndata.RData.Data.length > 0) {
                                    let column = rtndata.RData.Cols;
                                    var tableColumn = [];
                                    for(let i = 0;i < column.length;i++)
                                    {
                                        let item = column[i];
                                        tableColumn.push({
                                            title: item.title,
                                            property: item.field
                                        });
                                    }
                                    let str = JSON.stringify(tableColumn);
                                    str += "\r";
                                    str += JSON.stringify(rtndata.RData.Data);
                                    let sql = btoa(encodeURIComponent(str));
                                    jsObj.PrintCustomJsonReport(this.CircStyleid, sql, this.$tool.getSession(this.$tool.loginuserno), "流转清单样式", "");
                                } else {
                                    this.$message.error("错误：没有要打印的数据！");
                                }
                                })
                            }
                        });
                        rLoading.close();
                    } else {
                        this.$alert("条码未送出，不能打印！", "提示");
                        return false;
                    }
                })
                .catch(() => {});
        },
        async getSonBarcodes(packbarcode) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "getSonBarcodes",
                        packbarcode: packbarcode,
                    },
                });
                return res;
            } catch (e) {
                this.$alert(e);
            }
        },
        ShowAllData() {
            //扫描一个新的条码回到未过滤的状态
            this.leftrowclick = "";
            this.$refs.leftxTable.clearCurrentRow();
        },
        //扫描条码
        async scanBarcode(txtbarcode) {
            if (!this.barcodearrivemode || !this.transtype) {
                this.$alert("请检查是否设置了标本扫描操作和本地打包类型！", "提示");
                return false;
            }
            //避免弹窗后按钮回车再次走入这个事件
            var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
            if (reg.test(this.txtbarcode)) {
                return false;
            }
            //每次扫描条码去掉左边的选中事件，使得中间可以显示所有
            this.ShowAllData();
            //保护后台reqbarcode（barcodearrivemode为default）时无操作反应（会返回重复数据但不应该显示）
            let fdata = this.master.filter((item) => item.barcode == txtbarcode);
            if (fdata.length > 0) {
                this.txtbarcode = txtbarcode + " 重复扫描";
                this.HightlightPos(this.txtbarcode);
                //定位到当前重复条码上，并显示明细
                this.RowSetHightlight(fdata[0]);
                return false;
            }
            if (!this.senduser) {
                this.$alert("请先选择送出人！", "提示", {
                    confirmButtonText: "确定",
                });
                return false;
            }

            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "scanbarcode",
                        barcode: txtbarcode,
                        senduser: this.senduser,
                    },
                });
                //console.log("scanBarcode", res);
                //消息显示处理
                switch (res.flag) {
                    case 1:
                        //成功->直接显示信息,接收部门待返回
                        res.master.cpperformdept = !res.recdept ? "0" : res.recdept;
                        res.master.cpperformlabgroup = !res.reclabgroupid ? "0" : res.reclabgroupid;
                        res.master.lastbarcode = res.master.barcode;
                        res.master.lastpatname = res.master.pat_name;
                        this.master.splice(0, 0, res.master);
                        this.detail = res.details;
                        this.$refs.xTable1.setCurrentRow(res.master);
                        this.txtbarcode = txtbarcode + " 成功！";
                        break;
                    case -1:
                        if (this.rcv_dupnomsgbox == "0") {
                            //失败(有弹窗)->点确定->关闭dialog
                            this.txtbarcode = this.txtbarcode + this.returnmsg(res.msgList);
                            let msg1 = txtbarcode + ",";
                            this.msglist = await this.msginfoList(res.msgList, msg1); //弹窗显示签收消息
                            await this.rcvmsgfault(-1, "", "");
                        } else if (this.rcv_dupnomsgbox == "2") {
                            //this.$message(this.returnmsg(res.msgList));
                            this.$message.error(this.txtbarcode + "  " + this.returnmsg(res.msgList));
                            this.txtbarcode = this.txtbarcode + "  " + this.returnmsg(res.msgList);
                        } else {
                            this.txtbarcode = this.txtbarcode + "  " + this.returnmsg(res.msgList);
                        }

                        // 显示无效的数据
                        if (this.rcv_showinvalid == "1") {
                            if (res.master != null) {
                                res.master.cpperformdept = !res.recdept ? "0" : res.recdept;
                                res.master.cpperformlabgroup = !res.reclabgroupid ? "0" : res.reclabgroupid;
                                res.master.lastbarcode = res.master.barcode;
                                res.master.lastpatname = res.master.pat_name;
                                let data = this.master.findIndex((item) => item.barcode == res.master.barcode);
                                if (data < 0) {
                                    if (this.barcodearrivemode != "2" || (this.barcodearrivemode == "2" && res.master.req_stat >= "4")) {
                                        this.master.splice(0, 0, res.master);
                                        this.$refs.xTable1.setCurrentRow(res.master);
                                        this.detail = res.details;
                                    }
                                } else {
                                    this.$refs.xTable1.setCurrentRow(data[0]);
                                }
                            }
                        }

                        break;
                    case 0:
                        if (res.master == null) {
                            this.txtbarcode = this.txtbarcode + " 申请单不存在！";
                        } else {
                            this.txtbarcode = this.txtbarcode + this.returnmsg(res.msgList);
                            let msg2 = txtbarcode + "是否签收？此为";
                            this.msglist = await this.msginfoList(res.msgList, msg2); //弹窗显示消息
                            let retdata = await this.rcvmsgfault(0, txtbarcode, res.rcvmsg);
                            //console.log("retdata", retdata);
                            if (!retdata) break;
                            switch (retdata.flag) {
                                case 1:
                                    //条码签收成功
                                    retdata.master.cpperformdept = !res.recdept ? "0" : res.recdept;
                                    retdata.master.cpperformlabgroup = !res.reclabgroupid ? "0" : res.reclabgroupid;
                                    retdata.master.lastbarcode = retdata.master.barcode;
                                    retdata.master.lastpatname = retdata.master.pat_name;
                                    this.master.splice(0, 0, retdata.master);
                                    this.detail = res.details;
                                    this.$refs.xTable1.setCurrentRow(retdata.master);
                                    this.txtbarcode = txtbarcode + " 成功！";
                                    break;
                                case -1:
                                    //条码签收失败
                                    let msg3 = txtbarcode + "签收失败,";
                                    this.msglist = await this.msginfoList(retdata.msgList, msg3); //弹窗显示签收消息
                                    await this.rcvmsgfault(-1, "", "");
                                    break;
                            }
                        }
                        break;
                    case -99:
                        //出错->直接显示信息
                        this.txtbarcode = this.txtbarcode + " 出错!" + res.errmsg;
                        break;
                    case 98: //98/99标识包条码返回
                        this.txtbarcode = this.txtbarcode + " 出错!" + res.msg;
                        break;
                    case 99: //99表示获取成功
                        let data = res.pkgdetail;
                        let alen = res.pkgdetail.length;
                        if (this.barcodearrivemode == "0") {
                            let tans = res.trans;
                            if (tans.status == "1") {
                                // 明细添加到主表记录里面
                                for (const row of data) {
                                    this.txtbarcode = row.barcode;
                                    this.scanBarcode(row.barcode);
                                }
                                if (this.receivesendmode == "1") {
                                    this.isused = true;
                                }
                                this.hidpackbarcode = row.packagebarcode;
                            } else {
                                this.txtbarcode = tans.packagebarcode + " 该包条码已接收完成!";
                            }
                        } else {
                            // console.log("data", res.pkgdetail);
                            this.packagedata = await [];
                            this.reBarcodeMsgList = await [];
                            this.dialogPackageRcv = true;
                            if (data && data.length > 0) {
                                let barnum = 0;
                                for (const item of data) {
                                    if (item.req_stat == null) {
                                        let gitem = await this.getbarcodeinfo(item.barcode);
                                        if (!gitem) {
                                            //没有错误，但是申请单没找到
                                            await this.packagedata.push(item);
                                        } else {
                                            //找到申请单
                                            if (gitem != "-1") {
                                                await this.packagedata.push(gitem);
                                            }
                                        }
                                    } else {
                                        await this.packagedata.push(item);
                                    }
                                    barnum++;
                                    this.remindstr = await ("正在获取第" + barnum + "个条码信息，条码号" + item.barcode + " (" + barnum + "/" + alen + ")");
                                }
                                this.trans = res.trans.packagebarcode + "|" + res.trans.transtype;
                                this.remindstr = await ("所有条码信息获取完成" + " (" + alen + "/" + alen + ")");
                            } else {
                                this.packagedata = [];
                                this.remindstr = await ("没有获取到条码信息" + " ( 0 / 0)");
                            }
                        }
                        break;
                }
                this.HightlightPos(this.txtbarcode);
            } catch (e) {
                console.log("error", e);
            }
        },
        rcvmsgfault(index, barcode, rcvmsg) {
            this.autoFocusBarcode();
            switch (index) {
                case -1: //失败(有弹窗)->点确定->关闭dialog
                    return new Promise((s, f) => {
                        this.$refs.edialog01.ShowDialog().then(() => {
                            s();
                            return;
                        });
                    });
                case 0: //提示(有弹窗)->是与否->走入dialogok
                    return new Promise((s, f) => {
                        this.$refs.edialog02
                            .ShowDialog()
                            .then(() => {
                                let data = this.dialogok(barcode, rcvmsg);
                                s(data);
                                return;
                            })
                            .catch(() => {
                                s();
                                return;
                            });
                    });
                case 1: //普通消息处理窗口
                    return new Promise((s, f) => {
                        this.$refs.edialog02
                            .ShowDialog()
                            .then(() => {
                                s();
                                return;
                            })
                            .catch(() => {
                                f();
                                return;
                            });
                    });
            }
        },
        async getbarcodeinfo(barcode) {
            const res = await this.$tool.request({
                url: "LIS/LIS2/LIS222",
                method: "post",
                data: {
                    action: "getbarcodeinfo",
                    barcode: barcode,
                },
            });
            switch (res.Item1) {
                case 0: //没有错误，但没有找到申请单
                    await this.$alert("条码号为[" + barcode + "]的申请单并没有找到！" + res.Item2);
                    return res.Item3; //值为空
                    break;
                case 1: //找到申请单
                    return res.Item3;
                    break;
                case -1: //失败
                    await this.$alert("获取失败，请检查接口！" + res.Item2);
                    return "-1";
                    break;
            }
        },
        //通用消息列表处理
        async msginfoList(msglist, name) {
            if (msglist.length > 0) {
                msglist.forEach((item) => {
                    item.Item1 = name + item.Item1;
                });
            }
            return msglist;
        },
        async dialogok(barcode, rcvmsg) {
            //提示时点击是走入签收条码
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "rcvbarcode",
                        barcode: barcode,
                        rcvmsg: rcvmsg,
                        // senduser: this.senduser
                    },
                });
                return res;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        //统一设置返回消息放入数组
        returnmsg(msglist) {
            var msg = [];
            if (msglist.length > 0) {
                msglist.forEach((item) => {
                    msg.push(item.Item1);
                });
            }
            return msg;
        },
        appendDialog(data, packagebarcode) {
            console.info("999999");
            console.info("appendDialog ===this.data.length==="+data[0].barcode);
            this.specimenData = data;
            this.packagebarcode = packagebarcode;
            this.specimenkey++;
            this.dialogSpecimenRcv = true;
            this.reBarcodeMsgList = [];
        },
        async packageCancel(object, isend) {
            // this.packagedata = await [];
            // this.packmaster = await [];
            this.dialogPackageRcv = false;
            // this.HightlightPos(this.txtbarcode);

            if (object.length > 0) {
                if (this.rcv_showinvalid == "1") {
                    //列表中显示无效签收的数据
                } else {
                    object = object.filter((item) => item.rcvflag == "1"); //过滤出有效签收的数据
                }

                for (const master of object) {
                    //  console.log("calmaster", master);
                    let data = this.masterList.findIndex((item) => item.barcode == master.barcode);
                    if (data < 0) {
                        // this.reqgroupnaInfo(master, this); //统计分单类别信息
                        //this.masterList.push(master);
                        this.master.splice(0, 0, master);
                    }
                }
            }
            this.txtbarcode = "请扫描条码号";
            this.$refs.barcode.focus();
            // this.barcodeholder = "请扫描条码号";

            // await this.RowSetHightlight();
        },
        async RetPackageChange(object, isend) {
            if (object) {
                if (this.master.length > 0) {
                    let data = this.master.filter((item) => item.barcode == object.barcode);
                    if (data.length == 0) {
                        this.master.push(object);
                        await this.RowSetHightlight(object);
                    } else {
                        let ret = object.barcode + "重复扫描！";
                        this.reBarcodeMsgList.push(ret);
                        await this.$alert(ret);
                    }
                } else {
                    this.master.push(object);
                    await this.RowSetHightlight(object);
                }
            }
            if (isend) {
                this.specimenData = await [];
                this.dialogSpecimenRcv = false;
                this.dialogPackageRcv = false;
                await this.RowSetHightlight(object);
                if (this.reBarcodeMsgList.length > 0) {
                    //存在重复扫描消息
                    let retall = "以下条码发生错误,请核对！</br>" + this.reBarcodeMsgList.join("</br>");
                    await this.$alert(retall, "提示", { dangerouslyUseHTMLString: true });
                }
            }
            this.HightlightPos(this.txtbarcode);
        },
        async specimenCancel(object) {
            this.specimenData = await [];
            this.dialogSpecimenRcv = false;
            this.dialogPackageRcv = false;
            this.HightlightPos(this.txtbarcode);
            if (object.length > 0) {
                if (this.rcv_showinvalid == "1") {
                    //列表中显示无效签收的数据
                } else {
                    object = object.filter((item) => item.rcvflag == "1"); //过滤出有效签收的数据
                }

                for (const master of object) {
                    let data = this.masterList.findIndex((item) => item.barcode == master.barcode);
                    if (data < 0) {
                        this.master.splice(0, 0, master);
                    }
                }
            }
            this.txtbarcode = "请扫描条码号";
            this.$refs.barcode.focus();
            // await this.RowSetHightlight();
        },
        async RetSpecimenChange(object, isend) {
            if (object) {
                if (this.master.length > 0) {
                    let data = this.master.filter((item) => item.barcode == object.barcode);
                    if (data.length == 0) {
                        //      console.log("specimen", object);
                        this.master.push(object);
                        await this.RowSetHightlight(object);
                    } else {
                        let ret = object.barcode + "重复扫描！";
                        this.reBarcodeMsgList.push(ret);
                        await this.$alert(ret);
                    }
                } else {
                    this.master.push(object);
                    await this.RowSetHightlight(object);
                }
            }
            if (isend) {
                this.specimenData = await [];
                this.dialogSpecimenRcv = false;
                this.dialogPackageRcv = false;
                await this.RowSetHightlight(object);
                if (this.reBarcodeMsgList.length > 0) {
                    //存在重复扫描消息
                    let retall = "以下条码发生错误,请核对！</br>" + this.reBarcodeMsgList.join("</br>");
                    await this.$alert(retall, "提示", { dangerouslyUseHTMLString: true });
                }
            }
            this.HightlightPos(this.txtbarcode);
        },
        async RowSetHightlight(row) {
            // let row = this.master[0];
            if (!!row) {
                this.$refs.xTable1.setCurrentRow(row);
                this.$refs.xTable1.scrollToRow(row);
                await this.Exedetailretrieve(row);
            } else {
                row = this.master[0];
                this.$refs.xTable1.setCurrentRow(row);
                await this.Exedetailretrieve(row);
            }
        },
        btnSetting() {
            this.dialogSetting = true;
        },
        RowClassName({ row }) {
            return this.$pub.getreqstatclass(row.req_stat);
        },
        cellClassName ({ row, column }) {
            let curr_row = this.$refs.xTable1.getCurrentRow();
            if(curr_row.barcode == row.barcode) {
                return "selRow";
            }
        },
        // 历史记录查询
        BtnHistoryQuery() {
            this.dialogHistoryTableVisible = true;
            this.startdt = new Date();
            this.enddt = new Date();
            //this.create_user = this.$tool.getSession(this.$tool.loginuserno);
            this.QueryHistoryData();
        },
        // 弹窗 查询按钮操作
        btnHistoryQuery() {
            this.QueryHistoryData();
        },
        // 历史数据查询
        QueryHistoryData() {
            this.historyloading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "get_Historydata",
                        startdt: this.startdt,
                        enddt: this.enddt,
                        createuser: this.create_user,
                        pagrcvdept: this.pagrcvdept,
                    },
                })
                .then((res) => {
                    this.historytableData = res.data;
                    this.historyloading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        loginbarcodes() {
            this.btnClear();
            let row = this.$refs.hTable.getCurrentRow();
            // 关闭弹窗
            this.dialogHistoryTableVisible = false;
            // 获取包条码中的条码明细
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "get_reqdetail",
                        packagebarcode: row.packagebarcode,
                    },
                })
                .then((res) => {
                    let details = res.data;
                    for (const row of details) {
                        this.txtbarcode = row.barcode;
                        this.scanBarcode(row.barcode);
                    }
                    if (this.receivesendmode == "1") {
                        this.isused = true;
                    }
                    this.hidpackbarcode = row.packagebarcode;
                    //this.historytableData = res.data;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        // 交接按钮
        btnRecive() {
            this.isused = false;
            let list = this.master;
            if (list.length == "0") {
                this.$message("无数据，请重新操作");
                this.autoFocusBarcode();
                return;
            }
            // 弹窗提示是否 交接
            this.$confirm(`是否交接吗？`, {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    if(this.handovershowlogin=="1"){
                    this.$rm_Login({
                        type: "请输入工号和密码",
                        btn: {
                            confirmBtnText: "确定",
                            cancelBtnText: "取消",
                        },
                    })
                        .then((res) => {
                            if (res.flag == "1") {
                                this.rechkuser = res.userid;
                                this.rechkusername = res.username;
                                this.recivedata(res.userid, list);
                            } else {
                                //登录失败
                                this.autoFocusBarcode();
                            }
                        })
                        .catch(() => {
                            this.autoFocusBarcode();
                            return false;
                        });
                        }
                        else{
                            this.rechkuser = this.$tool.getSession(this.$tool.loginuserno);
                            this.rechkusername = this.$tool.getSession(this.$tool.loginusername);
                            this.recivedata(this.rechkuser, list);
                        }
                        this.autoFocusBarcode();
                })
                .catch(() => {
                    this.autoFocusBarcode();
                    return false;
            });
        },

        // 接收数据
        recivedata(userno, list) {
            let barcodes = "";
            list.forEach((item) => {
                if (barcodes == "") {
                    barcodes = item.barcode;
                } else {
                    barcodes = barcodes + "," + item.barcode;
                }
            });
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS222",
                    method: "post",
                    data: {
                        action: "ReciveBarcodes",
                        userno: userno,
                        barcode: barcodes,
                        packagebarcode: this.hidpackbarcode,
                    },
                })
                .then((res) => {
                    if (res.flag == 1) {
                        this.$message("交接完成！");
                        if (this.receivesendmode == "1") {
                            this.txtbarcode = "";
                            this.$refs.barcode.focus();
                            this.master = [];
                            this.hidpackbarcode = "";
                            this.detail = [];
                        }
                    } else {
                        this.$message(res.msg);
                    }
                    this.autoFocusBarcode();
                })
                .catch((e) => {
                    this.$message(e);
                    this.autoFocusBarcode();
                });
        },
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 75px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 80px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.table1style tr td {
    padding: 0px 2px 2px 2px;
}

::v-deep .selRow {
    font-size: 1.3em;
    font-weight: 2000;
}
.table-bottom {
    position: absolute;
    left: 0px;
    bottom: 0%;
    z-index: 1;
    overflow: hidden;
    width: 100%;
}
</style>